<?php
session_start ();
require_once ("../commun/ouvre_base.php");

$_SESSION ['pathway'] = '..';
include_once ($_SESSION ['pathway'] . "/header.php");

if (! isset ( $_SESSION ['id'] ) or $_SESSION ['acces_genetique'] < 1) {
	echo "<table class='principale'><tr><td>Session expired</td></tr>";
	echo "<tr><td><a href='" . $_SESSION ['pathway'] . "/index.php'>Start</a></td></tr></table>";
} else {
	
	$edit = $_GET ['edit'];
	echo "<form action=\"../commun/see_clinique.php?edit=$edit&amp;view=activity&amp;from=edit\" method='post'  enctype='multipart/form-data'>";
	
	if (isset ( $_GET ['form'] ) and $_GET ['form'] != '') { // recherche par NIP (=par patient)
		$form = $_GET ['form'];
		echo "ACTIVITY RECORDS FOR PATIENT " . $form . "</p>";
		$liste_indexes = array ();
		$requete_recup_indexes = "SELECT * FROM `form_activite`
		WHERE `nip`= $form";
		$result_recup_indexes = mysql_query ( $requete_recup_indexes ) or die ( "Impossible de recupérer les indexes : " . mysql_error () );
		while ( $ligne = mysql_fetch_assoc ( $result_recup_indexes ) ) {
			array_push ( $liste_indexes, $ligne ['index'] );
		}
	} else if (isset ( $_GET ['edit'] ) and $_GET ['edit'] != '') { // recherche par form
		?><p>
	<a href="<?php echo $_SESSION['pathway']; ?>/index.php">Start</a> > <a
		href="<?php echo $_SESSION['pathway']; ?>/start.php">Home</a> > Edit
	activity record
</p><?php
		$liste_indexes = array (
				$_GET ['edit'] 
		);
	}
	
	$liste_nom_champs = array ();
	$liste_nom_champs_type = array ();
	$requete_recup_entete = "SELECT * FROM `form_activite_nom_champ`
	ORDER BY `ID_index_nom_champ` ASC";
	$result_recup_entete = mysql_query ( $requete_recup_entete ) or die ( "Impossible de recupérer les entetes : " . mysql_error () );
	while ( $ligne = mysql_fetch_assoc ( $result_recup_entete ) ) {
		$cle = $ligne ['champ'];
		$liste_nom_champs [$cle] = $ligne ['nom_champ'];
		$liste_nom_champs_type [$cle] = $ligne ['type'];
	}
	
	foreach ( $liste_indexes as $index ) {
		$requete_form_activite = "SELECT * FROM `form_activite`
		WHERE `index`= $index";
		$result_requete_form_activite = mysql_query ( $requete_form_activite ) or die ( "Impossible de recupérer les forms d'activité : " . mysql_error () );
		
		echo "<table class='principale' cellspacing='1' cellpadding='3' style='margin-top:0px; margin-left:0px; margin-right:0px; font-size:10px; position:relative; float:top; cols=27; '>";
		while ( $ligne = mysql_fetch_assoc ( $result_requete_form_activite ) ) {
			$cpt = 0;
			foreach ( array_keys ( $liste_nom_champs ) as $champ ) {
				if ($l == 0) {
					$l = 1;
					$style = " style='background-color:#EEF7FC;'";
				} else if ($l == 1) {
					$l = 0;
					$style = " style='background-color:#E6F2F8;'";
				}
				echo "<tr$style><td>" . $liste_nom_champs [$champ] . "</td>";
				echo "<td>";
				if (isset ( $_GET ['edit'] )) {
					echo $liste_nom_champs_type [$champ];
				}
				echo $ligne [$champ];
				if (isset ( $_GET ['edit'] )) {
					echo "\" />";
				}
				echo "</td></tr>";
			}
			$cpt ++;
		}
	}
	if (isset ( $_GET ['edit'] )) {
		echo "<tr><td><input type='submit' value='Save' /></td></tr>";
	}
	echo "</table>";
	echo "</form>";
}

include ($_SESSION ['pathway'] . "/footer.php");

?>

